package com.hkbigdata.sybx.mapper;

import com.hkbigdata.sybx.bean.UserInterest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yangjing
 * @creat 2025-05-30-10:28
 * @email 3010335359@qq.com
 */
@Mapper
public interface UserInterestMapper {
    /**
     * 插入用户兴趣选择
     * @param userInterest 用户兴趣实体
     * @return 影响行数
     */
    @Options(useGeneratedKeys = true, keyProperty = "interest_id")
    @Insert("INSERT INTO user_interest " +
            "(service_list, info_list, comm_list, user_id) " +
            "VALUES (#{serviceList,jdbcType=VARCHAR}, #{infoList,jdbcType=VARCHAR}, #{commList,jdbcType=VARCHAR}, #{user_id})")
    int insertUserInterest(UserInterest userInterest);

    /**
     * 查询所有用户兴趣选择
     * @return 用户兴趣列表
     */
//    @Select("select interest_id,service_list,info_list,comm_list,created_time,user_id from user_interest")
    @Select({
            "SELECT interest_id AS interest_id,",
            " service_list AS serviceList,",
            " info_list AS infoList,",
            " comm_list AS commList,",
            " created_time AS createTime,",
            " user_id AS user_id",
            "FROM user_interest"
    })
    List<UserInterest> getAllUserInterests();

    /**
     * 根据用户ID查询兴趣选择
     * @param userId 用户ID
     * @return 用户兴趣实体
     */
//    @Select("SELECT interest_id, service_list, info_list, comm_list, user_id, create_time " +
//            "FROM user_interest WHERE user_id = #{userId}")
//    @Select({
//            "SELECT service_list AS serviceList,",
//            " service_list AS serviceList,",
//            " info_list AS infoList,",
//            " comm_list AS commList",
//            " created_time AS createTime,",
//            " user_id AS user_id",
//            "FROM user_interest WHERE user_id = #{user_id}"
//    })
    @Select("SELECT interest_id AS interest_id, service_list AS serviceList," +
            " info_list AS infoList, comm_list AS commList," +
            " created_time AS createTime," +
            " user_id AS user_id FROM user_interest WHERE user_id = #{userId}")
    UserInterest getUserInterestByUserId(String userId);
}

